package com.ruoyi.match.controller;





import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.match.domain.FenClass;
import com.ruoyi.match.service.MatchUserEquipmentService;
import com.ruoyi.match.service.MatchUserService;

import com.ruoyi.match.domain.MatchUserEquipment;
import com.ruoyi.match.domain.MatchUserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author WYC
 * @since 2021-03-18
 */
@RestController
@RequestMapping("/match/admin")
@Api(tags = "adminBangding")
public class MatchUserEquipmentController extends BaseController {
    @Autowired
    private MatchUserEquipmentService matchUserEquipmentService;
    @Autowired
    private MatchUserService matchUserService;

    @ApiOperation(value = "查询申请的绑定", notes = "查询申请的绑定")
    @ApiImplicitParams({
            @ApiImplicitParam(name ="page" , value = "开始页码",required = false, defaultValue = "1",dataType = "int",paramType = "query"),
            @ApiImplicitParam(name ="size" , value = "每页显示的条目数",required = false,defaultValue = "10",dataType = "int",paramType = "query"),
            @ApiImplicitParam(name ="phone" , value = "用户电话号",required = false,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name ="equipmentId" , value = "设备id",required = false,dataType = "String",paramType = "query"),
    })
    @GetMapping("getAllBangDing")
    public AjaxResult getAll(
            @RequestParam(value = "page", required = false) Integer page,
            @RequestParam(value = "size", required = false) Integer size ,
            @RequestParam(value = "phone",required = false) String phone,
            @RequestParam(value = "equipmentId",required = false) String equipmentId)
    {
        if ( page != null && size != null) {
            PageHelper.startPage(page, size);
        }
        List<MatchUserEquipment> list = matchUserEquipmentService.selectAll(phone,equipmentId);
        if ( page != null && size != null) {


            PageInfo<MatchUserEquipment> pageInfo = new PageInfo<>(list);
            return AjaxResult.success(pageInfo.getList(), (int) pageInfo.getTotal());

        }else{
            return AjaxResult.success(list);
        }

    }
    @ApiImplicitParams({

            @ApiImplicitParam(name ="phone" , value = "用户电话号",required = true,dataType = "String",paramType = "form"),
            @ApiImplicitParam(name ="equipmentId" , value = "设备id",required = true,dataType = "String",paramType = "form"),
    })
    @ApiOperation(value = "同意绑定", notes = "")
    @PostMapping(value = "agree")
    public AjaxResult bangding( String phone,
                               String equipmentId)
    {
        matchUserEquipmentService.bangding(phone,equipmentId);
        return AjaxResult.success();
    }
    @ApiImplicitParams({
            @ApiImplicitParam(name ="phone" , value = "用户电话号",required = true,dataType = "String",paramType = "form"),
            @ApiImplicitParam(name ="equipmentId" , value = "设备id",required = true,dataType = "String",paramType = "form"),
    })
    @ApiOperation(value = "拒接绑定", notes = "")
    @PostMapping(value = "noagree",consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
    public AjaxResult jujue(String phone,
                               String equipmentId)
    {
        matchUserEquipmentService.jujue(phone,equipmentId);
        return AjaxResult.success();
    }






    @ApiOperation(value = "后端登录", notes = "后端登录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone", value = "电话", required = true ,dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "password", value = "密码",required = true , dataType = "String", paramType = "form")

    })
    @PostMapping(value = "/login",consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
    public AjaxResult login(@RequestParam(value = "phone",required = true) String phone,
                            @RequestParam(value = "password",required = true) String password)
    {

        matchUserService.Hlogin(phone,password);
        return AjaxResult.success();

    }

    @ApiOperation(value = "查询所有用户", notes = "查询所有用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name ="page" , value = "开始页码",required = false, defaultValue = "1",dataType = "int",paramType = "query"),
            @ApiImplicitParam(name ="size" , value = "每页显示的条目数",required = false,defaultValue = "10",dataType = "int",paramType = "query"),
                    @ApiImplicitParam(name ="classId" , value = "班级id",required = false,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name ="name" , value = "姓名",required = false,dataType = "String",paramType = "query"),
    })
    @GetMapping("getAllUser")
    public AjaxResult getAllUser(
            @RequestParam(value = "page", required = false) Integer page,
            @RequestParam(value = "size", required = false) Integer size ,
            @RequestParam(value = "classId",required = false) String classId,
            @RequestParam(value = "name",required = false) String name){
        if ( page != null && size != null) {
            PageHelper.startPage(page, size);
        }
        List<MatchUserVo> list = matchUserService.selectAll(classId,name);
        if ( page != null && size != null) {


            PageInfo<MatchUserVo> pageInfo = new PageInfo<>(list);
            return AjaxResult.success(pageInfo.getList(), (int) pageInfo.getTotal());

        }else{
            return AjaxResult.success(list);
        }

    }
    @ApiOperation("批量学生分班")
    @PostMapping("/fenban")
    @ApiImplicitParams({
            @ApiImplicitParam(name ="fenClass" , required = false,dataType = "FenClass",paramType = "body"),
    })
    public AjaxResult remove(@RequestBody FenClass fenClass)
    {
        return toAjax(matchUserService.updateBan(fenClass.getIds(),fenClass.getClassId()));
    }
}

